'use strict';

const db = uniCloud.database();

exports.main = async (event, context) => {
  const { consultantIds } = event;

  console.log('Received consultantIds:', consultantIds);

  if (!Array.isArray(consultantIds) || consultantIds.length === 0) {
    return {
      code: 400,
      message: '参数 consultantIds 必须为非空数组'
    };
  }

  try {
    const res = await db.collection('consultants')
      .where({
        user_id: db.command.in(consultantIds)
      })
      .get();

    return {
      code: 200,
      data: res.data
    };
  } catch (err) {
    console.error('查询失败:', err);
    return {
      code: 500,
      message: '查询咨询师信息失败',
      error: err
    };
  }
};
